package com.tx.core.mybatis.plus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;

/**
 * <pre>
 * 功能简述: 默认的MybatisPlus的MetaObjectHandler实现
 * </pre>
 *
 * @author PengQingyang
 * 创建时间 [2024/4/9]
 */
@Slf4j
public class DefaultMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        Date now = new Date();
        this.setFieldValByName("createTime",now,metaObject);
        this.setFieldValByName("createDate",now,metaObject);

        this.setFieldValByName("updateTime",now,metaObject);
        this.setFieldValByName("updateDate",now,metaObject);
        this.setFieldValByName("lastUpdateTime",now,metaObject);
        this.setFieldValByName("lastUpdateTime",now,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Date now = new Date();
        this.setFieldValByName("updateTime",now,metaObject);
        this.setFieldValByName("updateDate",now,metaObject);
        this.setFieldValByName("lastUpdateTime",now,metaObject);
        this.setFieldValByName("lastUpdateTime",now,metaObject);
    }
}
